package com.ramos.kuaixiao.utils;

import android.content.SharedPreferences;

import com.ramos.kuaixiao.App;

import java.util.Set;


public class SharedPreference {
    public static String getPreferString(String key) {
        SharedPreferences sp = App.mContext.getSharedPreferences("user", 0);
        return sp.getString(key, "");
    }

    public static void setPreferString(String key, String value) {
        SharedPreferences sp = App.mContext.getSharedPreferences("user", 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.putString(key, value);
        editor.apply();
    }

    public static void clear() {
        SharedPreferences sp = App.mContext.getSharedPreferences("user", 0);
        SharedPreferences.Editor editor = sp.edit();
        //清空数据
        editor.remove("password");
        editor.remove("phone");
        editor.remove("email");
        editor.remove("phone");
        editor.remove("dealerName");
        editor.remove("orgName");
        //editor.clear();
        editor.apply();
    }

    public static void setPreferBoolean(String key, boolean value) {
        SharedPreferences settings = App.mContext.getSharedPreferences("user", 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean(key, value);
        editor.apply();
    }

    public static boolean getPreferBoolean(String key) {
        SharedPreferences sp = App.mContext.getSharedPreferences("user", 0);
        return sp.getBoolean(key, false);
    }

    public static int getPreferInteger(String key) {
        SharedPreferences sp = App.mContext.getSharedPreferences("user", 0);
        return sp.getInt(key, 0);
    }

    public static void setPreferInteger(String key, int value) {
        SharedPreferences settings = App.mContext.getSharedPreferences("user", 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putInt(key, value);
        editor.apply();
    }

    public static void setPreferSet(String key, Set<String> value) {
        SharedPreferences settings = App.mContext.getSharedPreferences("user", 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putStringSet(key, value);
        editor.apply();
    }

    public static Set<String> getPreferSet(String key) {
        SharedPreferences settings = App.mContext.getSharedPreferences("user", 0);
        return settings.getStringSet(key, null);
    }

    public static boolean hasPreferString(String key) {
        SharedPreferences sp = App.mContext.getSharedPreferences("user", 0);
        return sp.contains(key);
    }
}